#include <iostream>
#include <map>
#include <set>
#include <string>
using std::cout;
using std::endl;

void TestMap1() {
  std::map<int, std::string> m1;
  m1.insert({4, "hello"});
  m1.insert({4, "hello2"});
  m1.insert(std::pair<int, std::string>(2, "nihao"));
  m1.insert(std::make_pair(6, "zhong"));
  m1.insert(std::map<int, std::string>::value_type(3, "guo"));
  m1[5] = "world";

  cout << "map1>> ";
  for (auto& item : m1) {
    cout << item.first << ':' << item.second << ' ';
  }
  cout << endl;
}

void TestMap2() {
  std::string arr[] = {"ni", "hao", "ni", "shi"};
  std::map<std::string, int> m1;
  for (auto& item : arr) {
    ++m1[item];
  }

  cout << "map2>> ";
  for (auto& item : m1) {
    cout << item.first << ':' << item.second << ' ';
  }
  cout << endl;
}

void TestMultimap() {
  std::multimap<int, std::string> m1;
  m1.insert({4, "hello"});
  m1.insert({4, "hello2"});
  m1.insert(std::pair<int, std::string>(2, "nihao"));
  m1.insert(std::make_pair(6, "zhong"));
  m1.insert(std::map<int, std::string>::value_type(3, "guo"));
  // m1[5] = "world"; // not support

  cout << "multimap>> ";
  for (auto& item : m1) {
    cout << item.first << ':' << item.second << ' ';
  }
  cout << endl;
}

void TestSet() {
  std::set<int> s1;
  s1.insert(3);
  s1.insert(2);
  s1.insert(2);
  s1.insert(5);
  s1.insert(1);

  cout << "set>> ";
  for (auto& item : s1) {
    cout << item << ' ';
  }
  cout << endl;
}

void TestMultiset() {
  std::multiset<int> s1;
  s1.insert(3);
  s1.insert(2);
  s1.insert(2);
  s1.insert(5);
  s1.insert(1);

  cout << "multiset>> ";
  for (auto& item : s1) {
    cout << item << ' ';
  }
  cout << endl;
}

int main() {
  TestMap1();
  TestMap2();
  TestMultimap();
  TestSet();
  TestMultiset();
}